package com.hwadee.springboot.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hwadee.springboot.entity.R;
import com.hwadee.springboot.entity.Student;
import com.hwadee.springboot.service.StudentService;
import com.hwadee.springboot.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 86152
* @description 针对表【student】的数据库操作Service实现
* @createDate 2025-05-12 10:29:21
*/
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student>
    implements StudentService{
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public R login(String username, String password) {
        //从数据库中通过用户名查询用户信息,并将查询结果和密码比对
        Student student =studentMapper.findByUsername(username);
        if(student != null){
            if(student.getStudentaccount().equals(username) && student.getPassword().equals(password)){
                return R.ok().msg("登录成功").data(student);
            }
        }
        return R.error(400).msg("用户名或密码错误");
    }
    @Override
    public R updateStudent(Student student) {
        // 检查是否存在该学生
        Student student1=studentMapper.updateStudent(student);
        if(student1 != null){
            return R.ok().msg("更新成功").data(student1);
        }
        return R.error(400).msg("更新失败");
    }

    @Override
    public R deleteStudent(int studentId) {
        // 检查是否存在该学生
        Student student=studentMapper.deleteStudent(studentId);
        if(student!= null){
            return R.ok().msg("删除成功").data(student);
        }
        return R.error(400).msg("删除失败");
    }
}




